package com.qidian.mes.sys.service.impl;

import com.qidian.mes.pojo.OptionLog;
import com.qidian.mes.pojo.User;
import com.qidian.mes.sys.mapper.OptionLogMapper;
import com.qidian.mes.sys.service.OptionLogService;
import com.qidian.mes.util.dot.PagerDTO;
import com.qidian.mes.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.text.html.Option;
import java.util.List;

/**
 * @Author 小可怎么都睡不够
 * @Company 起点编程
 * @Description
 * @Time 2024/4/7 11:58
 */
@Service
public class OptionLogServiceImpl implements OptionLogService {
    @Autowired
    private OptionLogMapper optionLogMapper;
    @Override
    public QdResult saveLog(OptionLog log) {
        return QdResult.isSuccess(optionLogMapper.insertLog(log));
    }

    @Override
    public QdResult selectByPage(OptionLog log, Integer page, Integer limit) {
        if(log.getUsername() != null && !log.getUsername().equals("")){
            log.setUser(new User());
            log.getUser().setUsername(log.getUsername());
        }
        int start = (page - 1) * limit;
        List<OptionLog> list = optionLogMapper.selectByPage(log, start, limit);
        int total = optionLogMapper.selectCount(log);
        PagerDTO pagerDTO = new PagerDTO<>();
        pagerDTO.setPage(page);
        pagerDTO.setLimit(limit);
        pagerDTO.setData(list);
        pagerDTO.setTotal(total);
        return QdResult.success(pagerDTO);
    }

    @Override
    public QdResult queryById(Long logId) {
        return QdResult.success(optionLogMapper.selectByLogId(logId));
    }
}
